//
//  DefaultManager.m
//  HGY
//
//  Created by lanou3g on 15/10/30.
//  Copyright © 2015年 顾成辉. All rights reserved.
//

#import "DefaultManager.h"
#import "MenuModel.h"

@implementation DefaultManager

+ (instancetype)defaultManager
{
    static DefaultManager *manager = nil;
    static dispatch_once_t oneToKen;
    dispatch_once(&oneToKen, ^{
        manager = [[[self class] alloc] init];
        
    });
    return manager;
}

- (NSMutableArray *)AllArrayUrl
{
    if (!_AllArrayUrl) {
        _AllArrayUrl = [NSMutableArray array];
    }
    return _AllArrayUrl;
}

#pragma mark --- 热门美食
- (void)requestReMenMeiShiDataForReloadWithUrl:(NSString *)Url Block:(void (^)(NSArray *))block{

    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:Url] cachePolicy:(NSURLRequestUseProtocolCachePolicy) timeoutInterval:30.0];
        [request setHTTPMethod:@"GET"];
        
        NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
        
        NSURLSession *sesson = [NSURLSession sessionWithConfiguration:config];
        NSURLSessionDataTask *dataTask = [sesson dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            
            if (data == nil) {
                return ;
            }
            
            NSDictionary *Dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
            
            NSMutableArray *array = Dic[@"results"];
            self.ReMenMeiShiDataArray = [NSMutableArray array];
            for (NSDictionary *Dic1 in array) {
                MenuModel *model = [[MenuModel alloc] init];
                [model setValuesForKeysWithDictionary:Dic1];
                [self.ReMenMeiShiDataArray addObject:model];
            }
            
            dispatch_async(dispatch_get_main_queue(), ^{
                block(self.ReMenMeiShiDataArray);
            });
        }];
        [dataTask resume];
    });
}

#pragma mark -- 靓汤
- (void)requestLiangTangDataForReloadWithUrl:(NSString *)url Block:(void (^)(NSMutableArray *))block{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:(NSURLRequestUseProtocolCachePolicy) timeoutInterval:30.0];
        [request setHTTPMethod:@"GET"];
        
        NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
        
        NSURLSession *sesson = [NSURLSession sessionWithConfiguration:config];
        NSURLSessionDataTask *dataTask = [sesson dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            
            if (data == nil) {
                return ;
            }

            NSDictionary *Dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
            
            NSMutableArray *array = Dic[@"results"];
            self.LiangTangDataArray = [NSMutableArray array];
            for (NSDictionary *Dic1 in array) {
                MenuModel *model = [[MenuModel alloc] init];
                [model setValuesForKeysWithDictionary:Dic1];
                [self.LiangTangDataArray addObject:model];
            }
            
            
            dispatch_async(dispatch_get_main_queue(), ^{
                block(self.LiangTangDataArray);
            });
        }];
        [dataTask resume];
    });
}

#pragma mark -- 特色小吃
// 特色小吃
- (void)requestTeSeXiaoChiDataForReloadWithUrl:(NSString *)url Block:(void (^)(NSMutableArray *))block
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:(NSURLRequestUseProtocolCachePolicy) timeoutInterval:30.0];
        [request setHTTPMethod:@"GET"];
        
        NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
        
        NSURLSession *sesson = [NSURLSession sessionWithConfiguration:config];
        NSURLSessionDataTask *dataTask = [sesson dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            
            if (data == nil) {
                return ;
            }

            NSDictionary *Dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
            
            NSMutableArray *array = Dic[@"results"];
            self.TeSeXiaoChiDataArray = [NSMutableArray array];
            for (NSDictionary *Dic1 in array) {
                MenuModel *model = [[MenuModel alloc] init];
                [model setValuesForKeysWithDictionary:Dic1];
                [self.TeSeXiaoChiDataArray addObject:model];
            }
            
                         dispatch_async(dispatch_get_main_queue(), ^{
                block(self.TeSeXiaoChiDataArray);
            });
        }];
        [dataTask resume];
    });

}

#pragma mark -- 凉菜
- (void)requestLiangCaiDataForReloadWithUrl:(NSString *)url Block:(void (^)(NSArray *))block
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:(NSURLRequestUseProtocolCachePolicy) timeoutInterval:30.0];
        [request setHTTPMethod:@"GET"];

        NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
        
        NSURLSession *sesson = [NSURLSession sessionWithConfiguration:config];
        NSURLSessionDataTask *dataTask = [sesson dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            if (data == nil) {
                return ;
            }
            
            NSDictionary *Dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
            
            NSMutableArray *array = Dic[@"results"];
            self.LiangCaiDataArray = [NSMutableArray array];
            for (NSDictionary *Dic1 in array) {
                MenuModel *model = [[MenuModel alloc] init];
                [model setValuesForKeysWithDictionary:Dic1];
                [self.LiangCaiDataArray addObject:model];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                block(self.LiangCaiDataArray);
            });
        }];
        [dataTask resume];
    });

}

// 时尚饮品


//- (void)requestShiShangYinPinnDataForReloadWithUrl:(NSString *)url Block:(void (^)(NSArray *))block




- (void)requestShiShangYinPinDataForReloadWithUrl:(NSString *)url Block:(void (^)(NSMutableArray *))block

{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:(NSURLRequestUseProtocolCachePolicy) timeoutInterval:30.0];
        [request setHTTPMethod:@"GET"];
        
        NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
        
        NSURLSession *sesson = [NSURLSession sessionWithConfiguration:config];
        NSURLSessionDataTask *dataTask = [sesson dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            if (data == nil) {
                return ;
            }

            NSDictionary *Dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
            
            NSMutableArray *array = Dic[@"results"];
            self.ShiShangYinPinDataArray = [NSMutableArray array];
            for (NSDictionary *Dic1 in array) {
                MenuModel *model = [[MenuModel alloc] init];
                [model setValuesForKeysWithDictionary:Dic1];
                [self.ShiShangYinPinDataArray addObject:model];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                block(self.ShiShangYinPinDataArray);
            });
        }];
        [dataTask resume];
    });

}

#pragma mark -- 甜品
- (void)requestTianPinnDataForReloadWithUrl:(NSString *)url Block:(void (^)(NSArray *))block
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:(NSURLRequestUseProtocolCachePolicy) timeoutInterval:30.0];
        [request setHTTPMethod:@"GET"];
        
        NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
        
        NSURLSession *sesson = [NSURLSession sessionWithConfiguration:config];
        NSURLSessionDataTask *dataTask = [sesson dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            if (data == nil) {
                return ;
            }

            NSDictionary *Dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
            
            NSMutableArray *array = Dic[@"results"];
            self.TianPinnDataArray = [NSMutableArray array];
            for (NSDictionary *Dic1 in array) {
                MenuModel *model = [[MenuModel alloc] init];
                [model setValuesForKeysWithDictionary:Dic1];
                [self.TianPinnDataArray addObject:model];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                block(self.TianPinnDataArray);
            });
        }];
        [dataTask resume];
    });

}

#pragma mark -- 药膳美食
- (void)requestYaoShanShiLiaoDataForReloadWithUrl:(NSString *)url Block:(void (^)(NSArray *))block
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:(NSURLRequestUseProtocolCachePolicy) timeoutInterval:30.0];
        [request setHTTPMethod:@"GET"];
        
        NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
        
        NSURLSession *sesson = [NSURLSession sessionWithConfiguration:config];
        NSURLSessionDataTask *dataTask = [sesson dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            if (data == nil) {
                return ;
            }

            NSDictionary *Dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
            
            NSMutableArray *array = Dic[@"results"];
            self.YaoShanShiLiaoDataArray = [NSMutableArray array];
            for (NSDictionary *Dic1 in array) {
                MenuModel *model = [[MenuModel alloc] init];
                [model setValuesForKeysWithDictionary:Dic1];
                [self.YaoShanShiLiaoDataArray addObject:model];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                block(self.YaoShanShiLiaoDataArray);
            });
        }];
        [dataTask resume];
    });

}

#pragma mark -- 烘培
- (void)requestHongPeiDataForReloadWithUrl:(NSString *)url Block:(void (^)(NSArray *))block
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:(NSURLRequestUseProtocolCachePolicy) timeoutInterval:30.0];
        [request setHTTPMethod:@"GET"];
        
        NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
        
        NSURLSession *sesson = [NSURLSession sessionWithConfiguration:config];
        NSURLSessionDataTask *dataTask = [sesson dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            if (data == nil) {
                return ;
            }

            NSDictionary *Dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
            
            NSMutableArray *array = Dic[@"results"];
            self.HongPeiDataArray = [NSMutableArray array];
            for (NSDictionary *Dic1 in array) {
                MenuModel *model = [[MenuModel alloc] init];
                [model setValuesForKeysWithDictionary:Dic1];
                [self.HongPeiDataArray addObject:model];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                block(self.HongPeiDataArray);
                
            });
        }];
        [dataTask resume];
    });
    
}

- (NSArray *)addAllArrayUrl
{
    
    
    [self.AllArrayUrl addObjectsFromArray: self.ReMenMeiShiDataArray];
    [self.AllArrayUrl addObjectsFromArray:self.LiangTangDataArray];
    [self.AllArrayUrl addObjectsFromArray:self.TeSeXiaoChiDataArray];
    [self.AllArrayUrl addObjectsFromArray:self.LiangCaiDataArray];
      [self.AllArrayUrl addObjectsFromArray:self.ShiShangYinPinDataArray];

     [self.AllArrayUrl addObjectsFromArray:self.TianPinnDataArray];
    
    [self.AllArrayUrl addObjectsFromArray:self.YaoShanShiLiaoDataArray];
    [self.AllArrayUrl addObjectsFromArray:self.HongPeiDataArray];
    return self.AllArrayUrl;
    

}

- (NSArray *)getArray:(NSInteger)index
{
//    self.AllArrayUrl = [NSArray arrayWithObjects:@"ReMenMeiShiDataArray", @"LiangTangDataArray", @"TeSeXiaoChiDataArray", @"LiangCaiDataArray", @"ShiShangYinPinDataArray", @"TianPinnDataArray", @"YaoShanShiLiaoDataArray", @"HongPeiDataArray", nil];
   
    

    NSArray *array = [self addAllArrayUrl];
    return array[index];
   }





@end
